package com.vone.ui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicScrollBarUI;

public class MyVerticalScrollBarUI extends BasicScrollBarUI {
	private Color backColor=Color.white;
	
	 public MyVerticalScrollBarUI(){
		  super();
		 }
	 	
	/**
	 * 画滚动条中间按钮
	 */
	protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
		  int width = thumbBounds.width;
		  int height = thumbBounds.height;
		  Graphics2D g2 = (Graphics2D)g;
		  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
		          RenderingHints.VALUE_ANTIALIAS_ON);
		  
		  g2.translate(thumbBounds.x, thumbBounds.y);
		  g2.setColor(new Color(39,157,227));

		  g2.fillRoundRect(1, 1, width-2, height-2, 10, 10);
	}

		 protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
		  g.setColor(backColor);
		  g.fillRect(0, 0, scrollbar.getWidth(), scrollbar.getHeight());
//		  int x = trackBounds.x;
//		  int y = trackBounds.y;
//		  int width = trackBounds.width;
//		  int height = trackBounds.height;
//		  Graphics2D g2 = (Graphics2D)g;
//		  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
//		          RenderingHints.VALUE_ANTIALIAS_ON);
//		  g2.setComposite(AlphaComposite
//		    .getInstance(AlphaComposite.SRC_OVER, 0.1f));
//		  
//		  //g2.fill3DRect(x, y, width, height, true);
//		  g2.setComposite(AlphaComposite
//		    .getInstance(AlphaComposite.SRC_OVER, 1f));
//		  g2.setColor(Color.red);
//		 // g2.fill3DRect(x, y, 1, height+1, true);
		  if(trackHighlight == DECREASE_HIGHLIGHT) {
		      paintDecreaseHighlight(g);
		  } 
		  else if(trackHighlight == INCREASE_HIGHLIGHT)  {
		      paintIncreaseHighlight(g);
		  }
		 }

	protected JButton createIncreaseButton(int orientation) {
		JButton button = new BasicArrowButton(orientation){
			private static final long serialVersionUID = 1L;

			public void paint(Graphics g) {
			    Graphics2D g2 = (Graphics2D)g;
			    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			            RenderingHints.VALUE_ANTIALIAS_ON);
			    g2.setColor(new Color(39,157,227));
			    g2.drawLine(0,getHeight()/2,getWidth()/2,getHeight()-1);
			    g2.drawLine(getWidth()/2,getHeight()-1,getWidth(),getHeight()/2);
			//    g2.drawLine(0,getHeight()-1,getWidth(),getHeight()-1);
			}
		};
		button.setOpaque(false);
		return button;
	}

		 protected JButton createDecreaseButton(int orientation) {

		  
		  JButton button = new BasicArrowButton(orientation){
		   /**
			 * 
			 */
			private static final long serialVersionUID = 1L;

		public void paint(Graphics g) {
		    Graphics2D g2 = (Graphics2D)g;
		    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
		            RenderingHints.VALUE_ANTIALIAS_ON);
		    g2.setColor(new Color(39,157,227));
		    g2.drawLine(0,getHeight()/2,getWidth()/2,0);
		    g2.drawLine(getWidth()/2,0,getWidth(),getHeight()/2);
		//    g2.drawLine(0,0,getWidth()-1,0);
		   }
		  };
		  button.setOpaque(false);
		  return button;
		 }

		public Color getBackColor() {
			return backColor;
		}

		public void setBackColor(Color backColor) {
			this.backColor = backColor;
		}
}
